const libVoyager = require('datavoyager');
const axios = require('axios');
const queryString = require('query-string');

const container = document.getElementById("app");
const config = {
    showDataSourceSelector: true,
    hideHeader: true
};
// const data = undefined;
// const voyagerInstance = libVoyager.CreateVoyager(container, config, data);
//
// const data = {
//     "values": [
//         {"fieldA": "A", "fieldB": 28}, {"fieldA": "B", "fieldB": 55}, {"fieldA": "C", "fieldB": 43},
//         {"fieldA": "D", "fieldB": 91}, {"fieldA": "E", "fieldB": 81}, {"fieldA": "F", "fieldB": 53},
//         {"fieldA": "G", "fieldB": 19}, {"fieldA": "H", "fieldB": 87}, {"fieldA": "I", "fieldB": 52}
//     ]
// };
var parsed = queryString.parse(location.search);
// var datasets = [
//     {
//         name: 'Barley',
//         description: 'Barley yield by variety across the upper midwest in 1931 and 1932',
//         url: 'data/barley.json',
//         id: 'barley',
//         group: 'sample'
//     }
// ];
axios.get('/kylin/table/list/'+parsed.jid)
    .then(function (response) {
        localStorage.setItem('datasets', JSON.stringify(response.data));
        const data = {values:[]};

        const voyagerInstance = libVoyager.CreateVoyager(container, config, undefined);

    });


// axios.get('/kylin/columns/'+parsed.table)
//     .then(function (response) {
//         console.log('response columns: ', response.data);
//         axios.post('/kylin/query', {
//             columns: JSON.stringify(response.data),
//             task_id: parsed.task_id,
//             table: parsed.table
//         }).then(function (res) {
//             console.log(res.data[0]);
//             console.log(res.data[1]);
//             voyagerInstance.updateData({values: res.data});
//         });
//     });

//
// const voyagerInstance = libVoyager.CreateVoyager(container, undefined, undefined)
//
// const data: any = {
//     "values": [
//         {"fieldA": "A", "fieldB": 28}, {"fieldA": "B", "fieldB": 55}, {"fieldA": "C", "fieldB": 43},
//         {"fieldA": "D", "fieldB": 91}, {"fieldA": "E", "fieldB": 81}, {"fieldA": "F", "fieldB": 53},
//         {"fieldA": "G", "fieldB": 19}, {"fieldA": "H", "fieldB": 87}, {"fieldA": "I", "fieldB": 52}
//     ]
// };
//
// voyagerInstance.updateData(data);


